Add around_test hook so instrumentation can be scoped per test#797
Open
KyleOps wants to merge 1 commit into
Open
Add around_test hook so instrumentation can be scoped per test#797KyleOps wants to merge 1 commit into
KyleOps wants to merge 1 commit into
Conversation
TestRunner executes an entire run in one call stack (ExecuteTestRun -> start -> recursive run), so any tracing added around the worker collapses the whole run into a single trace. A full run is many minutes and can be tens of thousands of spans, which trace backends truncate at a per-trace size limit and no trace UI can usefully render. Wrap run_test in an overridable around_test(test) hook that yields by default. Downstream instrumentation can prepend or override it to open a distinct span or trace per test, correlated by the run id, without monkeypatching run_test's internals. The single-test early return is folded into a conditional so the wrapped block always runs to completion. Refs inferno-framework#796
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an overridable
TestRunner#around_test(test)hook so instrumentation can be scoped to a single test. Addresses #796.Motivation
TestRunnerruns an entire test run in one call stack (Inferno::Jobs::ExecuteTestRun#perform->TestRunner#start-> recursive#run). When a deployment adds distributed tracing (for example OpenTelemetry auto-instrumentation around the Sidekiq worker), the span at the top of that job becomes the trace root and every downstream request the run makes nests under it, so the whole run collapses into a single trace.That trace is long-lived (many minutes) and very large (we have seen roughly 10,000 spans in one run), which is hard to use for two reasons that are independent of any particular backend:
max_bytes_per_trace, 5 MB by default) and silently drop spans past it, so the tail of a large run is lost.The natural unit for a test runner is the test, but there is currently no seam to hang per-test instrumentation on without monkeypatching
run_test's body (which is fragile against internal changes).Change
around_test(test), which yields by default and can be overridden or prepended to wrap each test's execution (a distinct span or trace per test, a timing metric, and so on).run_testinaround_test(test) { ... }.update_parent_result(test.parent) if test_run.test_id.present?so the wrapped block always runs to completion (behaviour is unchanged; it just avoids areturnunwinding out of the hook block).No new dependencies. The hook is generic: tracing is the motivating case, but it works equally for metrics, timing, or logging.
Example (downstream, OpenTelemetry)
This turns one unbounded per-run trace into one bounded, queryable trace per test, correlated by
inferno.test_run_id.Tests
around_testyields and returns the block's value by default.around_testis invoked once per executed test during a run.bundle exec rspec spec/inferno/test_runner_spec.rbpasses (17 examples, 0 failures) andbundle exec rubocopis clean on the changed files.